package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * RESTful风格接口
 * @author stone
 * @date 2022/11/16 21:06
 */
@RestController
public class RestfulController {

    // @PathVariable → URI
    //localhost:8080/user/query/1
    //localhost:8080/user/query/25
    //localhost:8080/user/query/36
    @RequestMapping("user/query/{uriid}")
    public BaseRespVo pathVariable(@PathVariable("uriid") Integer id) {

        return BaseRespVo.ok();
    }
    /*@RequestMapping("user/query/*")
    public BaseRespVo pathVariable(HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        return BaseRespVo.ok();
    }*/

    //localhost:8080/user/login?username=songge&password=ligenli
    @RequestMapping("user/login")
    public BaseRespVo login(@RequestParam("username") String name,
                            @RequestParam("password") String pwd) {

        return BaseRespVo.ok();
    }
    // String split
    //localhost:8080/request/header
    @RequestMapping("request/header")
    public BaseRespVo requestHeader(@RequestHeader("Accept-Encoding")String[] acceptEncoding,
                                    @RequestHeader("Host")String host) {
        return BaseRespVo.ok();
    }

    // 想要获得songge这个cookie所对应的值
    //localhost:8080/cookie/value
    @RequestMapping("cookie/value")
    public BaseRespVo cookieValue(@CookieValue("songge")String value) {
        return BaseRespVo.ok();
    }

    //localhost:8080/session/put/ligenli
    @RequestMapping("session/put/{username}")
    public BaseRespVo sessionPut(@PathVariable("username") String username, HttpSession session) {
        session.setAttribute("username", username);
        return BaseRespVo.ok();
    }


    //localhost:8080/session/attribute
    @RequestMapping("session/attribute")
    public BaseRespVo sessionAttribute(@SessionAttribute("username")String username) {
        return BaseRespVo.ok();
    }


}
